package factory

import java.util._
import java.util.concurrent.ConcurrentHashMap

import config.{AliPayProperties, WXPayProperties}

object ActionFactory {

  //支付
  private[this] val payActions = new ConcurrentHashMap[Integer, PayAction]

  //查询
  private[this] val queryActions = new ConcurrentHashMap[Integer, QueryAction]

  //退款
  private[this] val refundActions = new ConcurrentHashMap[Integer, RefundAction]

  //支付宝支付相关配置
  var aliPayPropertiesMap = new HashMap[String, AliPayProperties]

  //微信支付相关配置
  var wxPayPropertiesMap = new HashMap[String, WXPayProperties]

  def setPayAction(payChannel: Integer, payAction: PayAction): Unit = payActions.putIfAbsent(payChannel, payAction)

  def setQueryAction(payChannel: Integer, queryAction: QueryAction): Unit = queryActions.putIfAbsent(payChannel, queryAction)

  def setRefundAction(payChannel: Integer, refundAction: RefundAction): Unit = refundActions.putIfAbsent(payChannel, refundAction)

  def setAliPayProperties(bizCode: String, aliPayProperties: AliPayProperties): Unit = aliPayPropertiesMap.put(bizCode, aliPayProperties)

  def setWXPayProperties(bizCode: String, wxPayProperties: WXPayProperties): Unit = wxPayPropertiesMap.put(bizCode, wxPayProperties)

  def getPayAction(payChannel: Integer): PayAction = payActions.get(payChannel)

  def getQueryAction(payChannel: Integer): QueryAction = queryActions.get(payChannel)

  def getRefundAction(payChannel: Integer): RefundAction = refundActions.get(payChannel)

  def getAliPayProperties(bizCode: String): AliPayProperties = aliPayPropertiesMap.get(bizCode)

  def getWXPayProperties(bizCode: String): WXPayProperties = wxPayPropertiesMap.get(bizCode)
}
